package br.com.salmos.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class OpenHelper extends SQLiteOpenHelper {
    
    private static final String DATABASE_NAME = "salmos.db";
    private static final int DATABASE_VERSION = 1;
    public static final String SALMOSPT_TABLE_NAME = "salmospt";
    public static final String SALMOSES_TABLE_NAME = "salmoses";
    public static final String SALMOSEN_TABLE_NAME = "salmosen";
    

    private final String CREATE_DATABASE = "CREATE TABLE salmoses ("+ 
                                            "id        INTEGER," +
                                            "livro     TEXT," +
                                            "capitulo  INTEGER," +
                                            "versiculo INTEGER," +
                                            "texto     TEXT," +
                                            "lido      INTEGER," +
                                            "PRIMARY KEY ( id ASC ));" +
                                            "CREATE TABLE salmosen ("+
                                            "id        INTEGER," +
                                            "livro     TEXT," +
                                            "capitulo  INTEGER," +
                                            "versiculo INTEGER," +
                                            "texto     TEXT," +
                                            "lido      INTEGER," +
                                            "PRIMARY KEY ( id ASC ));" +
                                            " CREATE TABLE salmospt ("+ 
                                            "id        INTEGER," +
                                            "livro     TEXT," +
                                            "capitulo  INTEGER," +
                                            "versiculo INTEGER," +
                                            "texto     TEXT," +
                                            "lido      INTEGER," +
                                            "PRIMARY KEY ( id ASC ));"
                                            ;
    private final String CREATE_TABLE_PT = "CREATE TABLE salmospt ("+ 
                                            "id        INTEGER," +
                                            "livro     TEXT," +
                                            "capitulo  INTEGER," +
                                            "versiculo INTEGER," +
                                            "texto     TEXT," +
                                            "lido      INTEGER," +
                                            "PRIMARY KEY ( id ASC ));";
    
    private final String CREATE_TABLE_ES = "CREATE TABLE salmoses ("+ 
								            "id        INTEGER," +
								            "livro     TEXT," +
								            "capitulo  INTEGER," +
								            "versiculo INTEGER," +
								            "texto     TEXT," +
								            "lido      INTEGER," +
								            "PRIMARY KEY ( id ASC ));";
    
    private final String CREATE_TABLE_EN = "CREATE TABLE salmosen ("+
								            "id        INTEGER," +
								            "livro     TEXT," +
								            "capitulo  INTEGER," +
								            "versiculo INTEGER," +
								            "texto     TEXT," +
								            "lido      INTEGER," +
								            "PRIMARY KEY ( id ASC ));";
    

    OpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);            
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_PT);
        db.execSQL(CREATE_TABLE_EN);
        db.execSQL(CREATE_TABLE_ES);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w("Example", "Upgrading database, this will drop tables and recreate.");
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSEN_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSES_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSPT_TABLE_NAME);
        onCreate(db);
    }
    
    public void dropDatabase(SQLiteDatabase db){
        
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSEN_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSES_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + SALMOSPT_TABLE_NAME);
        
    }
}